//
//  HomeContentViewCell.m
//  GuoBuGaForIphone
//
//  Created by zhangwo on 16/10/26.
//  Copyright © 2016年 GuoBuGa. All rights reserved.
//

#import "HomeContentViewCell.h"

@implementation HomeContentViewCell

@synthesize imageSize  = _imageSize;
@synthesize imageView  = _imageView;
@synthesize titleLabel = _titleLabel;
@synthesize data = _data;

- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        UIView *backgroundView = [[UIView alloc] initWithFrame:CGRectMake(-0.3, -0.3, frame.size.width+0.3, frame.size.height+0.3)];
        backgroundView.layer.borderColor = [UIColor colorWithHexString:@"0xC7C7C7"].CGColor;
        backgroundView.layer.borderWidth = 0.3;
        backgroundView.layer.masksToBounds = YES;
        [self addSubview:backgroundView];
        
        _imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 35, 35)];
        [_imageView setContentMode:UIViewContentModeScaleToFill];
        [backgroundView addSubview:_imageView];
        
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(18, 30+_imageSize.height, self.frame.size.width-36, 50)];
        _titleLabel.font = [UIFont systemFontOfSize:14.0];
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        _titleLabel.numberOfLines = 2;
        _titleLabel.textColor = [UIColor blackColor];
        [backgroundView addSubview:_titleLabel];
        
        //添加删除按钮
        _button = [[UIButton alloc] initWithFrame:CGRectMake(self.frame.size.width/3+50, 5, 22, 22)];
        _button.hidden = YES;
        [_button setBackgroundImage:[UIImage imageNamed:@"icon-hook.png"] forState:UIControlStateNormal];
        [_button setBackgroundImage:[UIImage imageNamed:@"icon-selected-hook.png"] forState:UIControlStateSelected];
        [backgroundView addSubview:_button];
    }
    return self;
}

//setter方法
- (void)setData:(NSDictionary *)data{
    _data = data;
    if ([[data objectForKey:@"id"] intValue] == 0) {
        [_imageView setImage:[UIImage imageNamed:[data objectForKey:@"image"]]];
    }else {
        [_imageView sd_setImageWithURL:[NSURL URLWithString:[data objectForKey:@"image"]]];
    }
    _titleLabel.text = [data objectForKey:@"title"];
}

- (void)layoutSubviews{
    [super layoutSubviews];
    
    CGFloat x = self.frame.size.width/3;
    _imageView.frame = CGRectMake(x, 20, _imageSize.width, _imageSize.height);
   
    _titleLabel.frame = CGRectMake(18, 30+_imageSize.height, self.frame.size.width-36, 30);
}

@end
